var user_id =  GetQueryString("user_id");
var trans_status = GetQueryString("trans_status");
$(function () {
    $("#jqGrid").jqGrid({
    	url: baseURL + 'client/manager/getBorrowBooks?userId='+user_id+'&transStatus='+trans_status,
        datatype: "json",
        colModel: [			
        	{ label: 'id', name: 'id', key: true,width:70 },
			{ label: '书籍名称', name: 'bookName',index:"book_name",width:100,align:'center' },
			{ label: 'ISBN', name: 'isbnNo',index:"isbn_no" ,width:100,align:'center' },
			{ label: 'RFID', name: 'rfidCode', index:"rfid_code",width:100 ,align:'center'},
			{ label: '借阅时间', name: 'createTime',index:"create_time",width:140 ,align:'center' },
			{ label: '归还时间', name: 'modifyTime',index:"modify_time",width:140 ,align:'center' },
			{ label: '借阅时长', name: 'timeCount',index:"time_count",width:80 ,align:'center',
				formatter:function(cellvalue, options, rowObject){
					if(rowObject.timeCount==null){
						return "0h";
					}else{
						return rowObject.timeCount+"h";
					}
				}
			},
			{ label: '借阅费用(元)',name:'transAmount',index:"trans_amount",width:100,align:'center',
				formatter:function(cellvalue, options, rowObject){
					if(rowObject.transAmount==null){
						return "0";//0,
					}else{
						return rowObject.transAmount;
					}
				}
			},
			{ label: '书柜号', name: 'outTradeNo',index:"out_trade_no" ,width:110 ,align:'center',sortable:false,
				formatter:function(cellvalue, options, rowObject){
					if(trans_status==20){
						return rowObject.shelfCode;//0,
					}else{
						return rowObject.restituteShelfCode==null?"":rowObject.restituteShelfCode;
					}
				}
			},
			{ label: '书格号', name: 'modifyTime',index:"modify_time",width:110 ,align:'center',sortable:false,
				formatter:function(cellvalue, options, rowObject){
					if(trans_status==20){
						return rowObject.gridCode;//0,
					}else{
						return rowObject.restituteGridCode==null?"":rowObject.restituteGridCode;
					}
				}
			},
			{ label: '操作', name: 'modifyTime',index:"modify_time",width:80 ,align:'center',sortable:false,
				formatter:function(cellvalue, options, rowObject){
					if(trans_status==20){
						//return '<a onclick=\"cancelBook(\"'+rowObject.rfidCode+'\",\"'+user_id+'\",\"'+rowObject.id+'\")>作废</a>';
						return '<a onclick=\"cancelBook(\''+rowObject.rfidCode+'\',\''+user_id+'\',\''+rowObject.id+'\')\">作废</a>';
					}else{
						return "";
					}
				}
			}
			//{ label: '积分', name: 'pointValue',index:"point_value",width:60,align:'center' },
			//{ label: '信用分', name: 'creditValue',index:"credit_value",width:60,align:'center'},
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50,100,200],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        autoScroll:true,
        shrinkToFit:false,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        }
        
    });
    /*创建jqGrid的操作按钮容器*/
    /*可以控制界面上增删改查的按钮是否显示*/
    //jQuery("#jqGrid").jqGrid('navGrid', '#jqGridPager', {edit : true,add : true,del : true});
    //表格宽度自适应
    $(function(){
       $(window).resize(function(){
          $("#jqGrid").setGridWidth($(window).width());
       });
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			bookName: null,
			isbnNo: null,
			rfidCode:null,
			borrowStartTime:null,
			borrowEndTime:null
        },
		showList: true,
		title: null,
		marketBook: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam', {
				postData : {
					'bookName' : vm.q.bookName,
					'isbnNo' : vm.q.isbnNo,
					'rfidCode' : vm.q.rfidCode,
					'borrowStartTime':vm.q.borrowStartTime,
					'borrowEndTime':vm.q.borrowEndTime
				},
				page : page
			}).trigger("reloadGrid");
		}
	}
});